package es.ats.codington.web.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.services.EventServiceImpl;

/**
 * Servlet implementation class DeleteEventServlet.
 */
@WebServlet("/DeleteEventServlet")
public class DeleteEventServlet extends HttpServlet {
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

    /**
     * Instantiates a new delete event servlet.
     *
     * @see HttpServlet#HttpServlet()
     */
    public DeleteEventServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * Do get.
	 *
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession(true);

		int idEvent = Integer.parseInt(request.getParameter("idEvent"));
		int row=0;
		
		try{		
			EventServiceImpl eve = new EventServiceImpl();
			Event evento = new Event();
			
			row = eve.deleteEvent(idEvent);
       
		 }catch(Exception theException){
		        System.out.println(theException); 
		 }
		
		  if(row!=0){
		      session.setAttribute("Session", 5);
		       //	 response.sendRedirect("listEventAdmin.jsp");
		       	 //*RequestDispatcher rd=request.getRequestDispatcher("login.jsp");  
		            //*rd.forward(request,response); 
		       	 
		     ListAllEventServlet list= new ListAllEventServlet();
		     list.sendListAllEvent(request, response);
		  }
		   else{	       	 
			   session.setAttribute("Session", 1);
		      response.sendRedirect("registerEvent.jsp");
		      //*RequestDispatcher rd=request.getRequestDispatcher("home.jsp");  
		      //*rd.include(request,response); 
		   }
				
	}

	/**
	 * Do post.
	 *
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
